<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>修改商户</title>
    <link rel="stylesheet" href="../../../../bangnuo/admin/layui/css/layui.css">
</head>

<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
     style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">商户编号</label>
        <div class="layui-input-inline">
            <input type="text" name="id" id="merchantsNumber" lay-verify="required" placeholder="请输入商户编号"
                   autocomplete="off" class="layui-input" readonly="readonly">
            <input type="hidden" name="id" id="merchantsUuid" lay-verify="required" placeholder="请输入id"
                   autocomplete="off" class="layui-input" readonly="readonly">
        </div>
        <div class="layui-form-mid layui-word-red" style="color: red;">商户编号不可修改</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商户名称</label>
        <div class="layui-input-inline">
            <input type="text" name="companyName" id="merchantsCompanyName" lay-verify="required" placeholder="请输入用户名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" id="merchantsUsername" lay-verify="required" placeholder="请输入登录名"
                   autocomplete="off" class="layui-input" readonly="readonly">
        </div>
        <div class="layui-form-mid layui-word-red" style="color: red;">商户登录名不可修改</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password" id="merchantsPassword" placeholder="请输入密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">负责人姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="name" id="merchantsName" lay-verify="required" placeholder="请输入负责人姓名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" id="merchantsPhone" lay-verify="required" placeholder="请输入手机号"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电子邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" id="merchantsEmail" lay-verify="required" placeholder="请输入邮箱账号"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支付宝账号</label>
        <div class="layui-input-inline">
            <input type="text" name="alipayNum" id="merchantsZFBUsername" lay-verify="required" placeholder="请输入支付宝账号"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职务</label>
        <div class="layui-input-inline">
            <input type="text" name="position" id="merchantsPosition" lay-verify="required" placeholder="请输入你的职务"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-red" style="color: red;">法人 董事长 总经理 市场经理 老板 老板娘 财务 行政 技术</div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">商户类型</label>
        <div class="layui-input-block">
            <input type="radio" id="merchantsType1" name="type" value="0" title="公司" checked>
            <input type="radio" id="merchantsType2" name="type" value="1" title="个人">
            <input type="radio" id="merchantsType3" name="type" value="2" title="个体户">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">账号状态</label>
        <div class="layui-input-block">
            <input type="radio" id="merchantsState1" name="status" value="1" title="正常" checked>
            <input type="radio" id="merchantsState2" name="status" value="0" title="冻结">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">通道</label>
        <div class="layui-input-block">
            <input type="radio" name="merchantsChannel" value="0" title="支付宝" checked>
            <input type="radio" name="merchantsChannel" value="1" title="微信">
        </div>
    </div>

    <div class="layui-form-item" lay-filter="channel">
        <label class="layui-form-label">申请通道状态</label>
        <div class="layui-input-block">
            <input type="radio" id="channel1" name="channelStatus" value="1" title="微信申请通过" checked>
            <input type="radio" id="channel2" name="channelStatus" value="2" title="支付宝申请通过">
            <input type="radio" id="channel3" name="channelStatus" value="3" title="建联申请通过">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级代理</label>
        <div class="layui-input-block" style="width: 200px;">
            <select name="merchantsIdAgentId" id="agentIdAgentId">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">专属业务员</label>
        <div class="layui-input-block" style="width: 200px;">
            <select name="employeeId" id="employeeId">
            </select>
        </div>
    </div>

    <!--<div class="layui-form-item" id="area-picker">
        <div class="layui-form-label">地址</div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="merchantsProvince" class="province-selector" data-value="广东省" lay-filter="province-1">
                <option value="">请选择省</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="merchantsCity" class="city-selector" data-value="深圳市" lay-filter="city-1">
                <option value="">请选择市</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="merchantsArea" class="county-selector" data-value="龙岗区" lay-filter="county-1">
                <option value="">请选择区</option>
            </select>
        </div>
    </div>-->
    <!--<div class="layui-form-item">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-inline">
            <input type="text" name="addressDetailed" id="merchantsAddress" lay-verify="required" placeholder="请输入详细地址"
                   autocomplete="off" class="layui-input">
        </div>
    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input type="text" name="remark" id="merchantsNote" placeholder="请输入备注" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-btn-container" style="padding-bottom: 10px; margin-left: 110px; margin-right: -110px;">
        <button class="layui-btn" lay-submit lay-filter="admin-form" data-type="">立即提交</button>
    </div>
</div>
</body>
<script src="../../../../bangnuo/admin/layui/layui.js"></script>
<script src="../../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<script>
    $("#merchantsPhone").blur(function () {
        var phone = /^[1][3,4,5,7,8][0-9]{9}$/; //"请输入正确的手机号"
        if(!phone.test($("#merchantsPhone").val())){
            layer.msg("请输入正确的电话号");
        }
    });
    $("#merchantsEmail").blur(function () {
        var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; //"邮箱格式不正确"
        if(!email.test($("#merchantsEmail").val())){
            layer.msg("请输入正确的邮箱号");
        }
    });
</script>
</script>

<script>
    //配置插件目录
    layui.config({
        base: '../../../../bangnuo/admin/'

    });
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'layarea'], function () {

        $.ajax({
            type: "GET",
            url: '/agentEntity/findAgent',
            dataType:"json",
            contentType: "application/json;charset=UTF-8",
            success: function(res){
                var html2 = '<option value="">'+res.object.companyName+'</option>';
                if(res.success){
                    $("#agentIdAgentId").html(html2);
                    form.render('select');
                }
            }
        });


        var layer = layui.layer
            , form = layui.form
            , layarea = layui.layarea;
        layarea.render({
            elem: '#area-picker',
            change: function (res) {
                //选择结果
                console.log(res);
            }
        });
    });
</script>
<script src="../../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<!--<script>
    layui.use(['form', 'upload', 'layer'], function() {

        var form = layui.form;

        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        $.ajax({
            url: '',
            dataType: 'json',
            type: 'get',
            success: function(data) {
                resultData = data.data;                       
                for(var x in resultData) {                            
                htmls += '<option value = "' + resultData[x].value + '">' + resultData[x].name + '</option>';                      
                } 
                $("#merchantsIdAgentId").html(htmls);
                form.render('select');

                //重新渲染 固定写法
            }
        })
    });
</script>-->

<!--<script>
    layui.use(['form', 'upload', 'layer'], function () {

        var form = layui.form;

        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        $.ajax({
            url: '',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.data;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].value + '">' + resultData[x].name + '</option>';
                }
                $("#merchantsIdAdminId").html(htmls);
                form.render('select');

                //重新渲染 固定写法
            }
        })
    });
</script>-->
<script type="text/javascript">
    layui.use(['form', 'upload', 'layer'], function () {
        var form = layui.form;
        $(document).ready(function () {
            //获取地址栏路径
            var url = window.location.href;
            //获取“=”的下标
            var pos = url.indexOf("=");
            //获取“=”后的全部字符（用户id）
            var id = url.substring(pos + 1, url.length);
            $.ajax({
                url: "/commercial/findById/" + id,
                contentType: "application/json;charset=UTF-8",
                type: "GET",
                success: function (res) {
                    $("#merchantsUuid").val(res.object.id);
                    $("#merchantsNumber").val(res.object.number);
                    $("#merchantsCompanyName").val(res.object.companyName)
                    $("#merchantsUsername").val(res.object.username);
                    $("#merchantsPassword").val(res.object.password);
                    $("#merchantsName").val(res.object.name);
                    $("#merchantsPhone").val(res.object.phone);
                    $("#merchantsEmail").val(res.object.email);
                    $("#merchantsZFBUsername").val(res.object.alipayNum);
                    $("#merchantsPosition").val(res.object.position);
                    $("#merchantsAddress").val(res.object.addressDetailed);
                    $("#merchantsNote").val(res.object.remark);
                    $("#channelStatus").val(res.object.channelStatus);
                    //账号状态
                    if (res.object.status == 1) {
                        $("#merchantsState1").attr("checked", "checked");
                        $("#merchantsState2").removeAttr("checked");
                        form.render();
                    } else {
                        $("#merchantsState1").removeAttr("checked");
                        $("#merchantsState2").attr("checked", "checked");
                        form.render();
                    }
                    //商户类型
                    if (res.object.type == 0) {
                        $("#merchantsType1").attr("checked", "checked");
                        $("#merchantsType2").removeAttr("checked");
                        $("#merchantsType3").removeAttr("checked");
                        form.render();
                    } else if (res.object.type == 1) {
                        $("#merchantsType1").removeAttr("checked");
                        $("#merchantsType2").attr("checked", "checked");
                        $("#merchantsType3").removeAttr("checked");
                        form.render();
                    } else {
                        $("#merchantsType1").removeAttr("checked");
                        $("#merchantsType2").removeAttr("checked");
                        $("#merchantsType3").attr("checked", "checked");
                        form.render();
                    }
                    //通道状态
                    if (res.object.type == 0) {
                        $("#channel1").attr("checked", "checked");
                        $("#channel2").removeAttr("checked");
                        $("#channel3").removeAttr("checked");
                        form.render();
                    } else if (res.object.type == 1) {
                        $("#channel1").removeAttr("checked");
                        $("#channel2").attr("checked", "checked");
                        $("#channel3").removeAttr("checked");
                        form.render();
                    } else {
                        $("#channel1").removeAttr("checked");
                        $("#channel2").removeAttr("checked");
                        $("#channel3").attr("checked", "checked");
                        form.render();
                    }

                    $.ajax({
                        type: "GET",
                        url: '/adminEntity/findAllByAgentId',
                        dataType:"json",
                        contentType: "application/json;charset=UTF-8",
                        success: function(res1){
                            var html2 = '<option value="">请选择</option>';
                            if(res1.success){
                                for(var i=0;i<res1.queryResult.list.length;i++){
                                    if(res1.queryResult.list[i].id == res.object.employeeId){
                                        html2 = html2 + '<option value="'+res1.queryResult.list[i].id+'" selected>'+res1.queryResult.list[i].name+'</option>';
                                    }else{
                                        html2 = html2 + '<option value="'+res1.queryResult.list[i].id+'">'+res1.queryResult.list[i].name+'</option>';
                                    }

                                }
                                $("#employeeId").html(html2);
                                form.render('select');
                            }
                        }
                    });

                }
            });
        });
    });
</script>
<!--加载表单组件样式-->
<script>
    layui.config({
        base: '../../../../bangnuo/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function () {
        var $ = layui.$,
            form = layui.form,
            upload = layui.upload;

        upload.render({
            elem: '#layuiadmin-upload-useradmin',
            url: layui.setter.base + 'json/upload/demo.js',
            accept: 'images',
            method: 'get',
            acceptMime: 'image/*',
            done: function (res) {
                $(this.item).prev("div").children("input").val(res.data.src)
            }
        });
    })
</script>
<!--获取表单信息，提交表单-->
<script type="text/javascript">
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(admin-form)', function (data) {
            console.log("修改表单执行");
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                type: "POST",
                url: "/commercial/update/" + data.field.id,
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify(data.field),
                async: true,
                success: function (data) {
                    if (data.success == true) {
                        layer.msg(data.message);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        console.log("index值", index)
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
            return false;
        });
    });
</script>
<!--关闭弹层-->
<script>
    layui.use('layer', function () {
        var $ = layui.$,
            layer = layui.layer,
            index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var active = {
            close: function () {
                var id = '#LAY_layer_iframe_demo',
                    mark = $('#LAY_mark');
                parent.layer.msg('修改成功');
                parent.layer.tips('Look here', id, {
                    time: 5000
                });
                window.parent.location.reload();
                parent.layer.close(index);
            }
        }
        $('.layui-btn-container .layui-btn').on('click', function () {
            var othis = $(this),
                type = othis.data('type');
            active[type] && active[type].call(this);
        });

        function cole(){
            var active = {
                close: function() {
                    parent.layer.msg('修改成功');
                    window.parent.location.reload();
                    parent.layer.close(index);
                }
            }
            $('.layui-btn-container .layui-btn').on('click', function() {
                var othis = $(this),
                    type = othis.data('type');
                active[type] && active[type].call(this);
            });
        }
    });
</script>

</html>